
class Solution {
public:
    bool check(int i,vector<int>& group,vector<int>& nums)
    {
        for(int k = 0;k < group.size();++k)
        {
            if(nums[i] != group[k])
            {
                return false;
            }
            ++i;
        }
        return true;
    }
    bool canChoose(vector<vector<int>>& groups, vector<int>& nums) {
        int i = 0,j = 0;
        int res = 0;
        while(i < nums.size() && j < groups.size())
        {
            if(check(i,groups[j],nums))
            {
                res++;
                i += groups[j].size();
                j += 1;
            }
            else{
                i += 1;
            }
        }
        return res == groups.size();
    }
};